package com.combetter.changxing.viewmodel.base;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.MutableLiveData;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;

import com.combetter.changxing.net.HttpRequest;

/**
 * Created by Mark.fan on 2018/5/10.
 */

public class BaseViewModel<T> extends AndroidViewModel {
    public Context mContext;
    private MutableLiveData<Object> mActivitChange = new MutableLiveData<>();

    /**
     * 网络操作
     * 单例模式
     */
    protected HttpRequest mHttpRequest;

    public BaseViewModel(@NonNull Application application) {
        super(application);
        mContext = application;
        mHttpRequest = HttpRequest.getInstance();
    }

    /**
     * 处理activity跳转之类操作
     *
     * @return
     */
    public MutableLiveData<Object> getActivityChange() {
        return mActivitChange;
    }

    /**
     * activity跳转
     *
     * @param cls
     */
    public void startActivity(Class<?> cls) {
        Intent intent = new Intent(mContext, cls);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

    /**
     * activity跳转
     *
     */
    public void startActivity(Intent intent) {
        mContext.startActivity(intent);
    }
}
